package com.googlecode.bip.xml.importe;

import java.sql.SQLException;
import javax.naming.NamingException;

/**
 *
 * @author Claude CHOISNET
 */
class SQLTopicLocal  extends Commiter implements Commitable
{
    private SQLTopic    parent;
    private String      idlocal;
    private String      topicname;
    private String      topicdescription;

    SQLTopicLocal()
    {
    }

    void setParent( SQLTopic parent )
    {
        if( parent == null ) {
            throw new NullPointerException( "parent SQLTopic is null" );
            }

        this.parent = parent;
    }

    void setIdLocal( String idlocal )
    {
        if( idlocal == null ) {
            throw new NullPointerException( "idlocal is null" );
            }

        this.idlocal = idlocal;
    }

    void setTopicName( String topicname )
    {
        if( topicname == null ) {
            throw new NullPointerException( "topicname is null" );
            }

        this.topicname = topicname;
    }

    void setTopicDescription( String topicdescription )
    {
        if( topicdescription == null ) {
            throw new NullPointerException( "topicdescription is null" );
            }

        this.topicdescription = topicdescription;
    }

    @Override
    public void commit() throws NamingException, SQLException
    {
        if( idlocal == null ) {
            throw new NullPointerException( "idlocal is null" );
            }
        if( topicname == null ) {
            throw new NullPointerException( "topicname is null" );
            }
        if( topicdescription == null ) {
            throw new NullPointerException( "topicdescription is null" );
            }

        String sql = "REPLACE INTO `topics_local` (`idtopic`, `idlocal`, `topicname`, `topicdescription`) VALUES ('"
            + parent.getIdTopic()
            + "','"
            + idlocal
            + "','"
            + topicname
            + "','"
            + topicdescription
            + "');";

        super.performeCommit( sql );
    }
}
